import request from '@/utils/axios'

export type ConfigType = {
  id: number | undefined
  category: string
  name: string
  key: string
  type: string
  dateType: string
  isTimerange: boolean
  value: string
  remark: string
  create_time?: Date
}

export interface ConfigPageReqType extends PageParam {
  name?: string
  key?: string
  create_time?: Date[]
}

/**
 * 基础配置接口
 */
export const ConfigApi = {
  // 新增
  create: (data: ConfigType) => {
    return request.post({ url: '/infra/config/create', data, is_mock: true })
  },
  // 修改
  update: (data: ConfigType) => {
    return request.put({ url: '/infra/config/update', data, is_mock: true })
  },
  // 删除
  delete: (id: number) => {
    return request.delete({ url: '/infra/config/delete?id=' + id, is_mock: true })
  },
  // 查询详情
  detail: (id: number) => {
    return request.get({ url: '/infra/config/detail?id=' + id, is_mock: true })
  },
  // 根据参数键名查询参数值
  value: (configKey: string) => {
    return request.get({ url: '/infra/config/get-value-by-key?key=' + configKey, is_mock: true })
  },
  // 查询分页列表
  page: (params: ConfigPageReqType) => {
    return request.get({ url: '/infra/config/page', params, is_mock: true })
  },
  // 导出
  export: (params: ConfigPageReqType) => {
    return request.get({ url: '/infra/config/export', params, is_mock: true })
  }
}
